package com.campus_information_portal.dao;

import com.campus_information_portal.entity.Material;
import com.campus_information_portal.entity.MaterialMaterialTypeTeacher;
import com.campus_information_portal.entity.MaterialType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author 20155873 张联富
 * @Description $Description$
 * @methodName $methodName$
 * @date $date$ $time$
 * @return $returns$
 */
public interface MaterialDao {
    /* *
     * @param meterial_state
     * @Description
     * @methodName
     * @author 20155873 张联富
     * @date 2018/4/19 14:56
     * @return
     */

    @Select("select * from Material where material_state=#{material_state} ")
    List<Material> findAllMaterial(@Param("material_state") int material_state);

    /**
     * @Description 资料上传
     * @author 20155878 鄢前州
     * @methodName MaterialUp
     * @returnType void
     * @create 11:08 2018/4/26
     **/
    @Insert("insert into Material(material_type_id,te_info_id,material_name,material_size,material_uptime,material_downtimes,material_state) " +
            "values(#{material.materialTypeId},#{material.teInfoId},#{material.materialName},#{material.materialSize},#{material.materialUptime},#{material.materialDowntimes},#{material.materialState})")
    public boolean AddMaterial(@Param("material") Material material, @Param("id") int id);

    /**
     * @Description 更新下载次数
     * @author 20155878 鄢前州
     * @methodName updatematerial_uptime
     * @returnType void
     * @create 10:40 2018/5/3
     **/
    @Update("update material set material_downtimes = #{material.materialDowntimes} where material_name=#{material.materialName}")
    public boolean updatematerial_uptime(@Param("material") Material material);//更新语句错误：关键字冲突： check the manual that corresponds to your MySQL server version for the right syntax to use near

    /**
     * @Description 根据资料id查询下载次数
     * @author 20155878 鄢前州
     * @methodName querymaterial_downtimesBymaterial_id
     * @returnType int
     * @create 11:45 2018/5/3
     **/
    @Select("select material_downtimes from Material where material_name=#{materialName}")
    public Integer querymaterial_downtimesBymaterialNme(@Param("materialName") String materialName);

    /**
     * @Class_name:
     * @Describe: 通过文件名查找文件ID
     * @Author: 20155878 鄢前州
     * @Creat_date: 15:12
     * @Creat_time: 2018/5/31
     **/
    @Select("select material_type_id from material_type where material_typeName=#{materialtypeName}")
    public String querymaterial_type_idBymaterial_typName(@Param("materialtypeName") String materialtypeName);

    /**
     * @Describe: 联合老师表资料表和资料类型表进行链表查询
     * @Author: 20155878 鄢前州
     * @Creat_date: 22:23
     * @Creat_time: 2018/6/1
     **/
    @Select("select material.* ,material_type.material_typeName,teacher.te_name "+
            "from material,material_type,teacher " +
            "WHERE material.material_type_id=material_type.material_type_id " +
            "and material.te_info_id=teacher.te_info_id")
    public List<MaterialMaterialTypeTeacher> queryAllMaterial();
    /**
     *
     * @Method_name:
     * @Describe: 添加资料料类型
     * @Author: 20155878 鄢前州
     * @Creat_date: 23:34
     * @Creat_time: 2018/6/1
     **/
    @Insert("insert into material_type(material_typeName) values(#{materialTypeName})")
    public boolean AddMaterialType(@Param("materialTypeName") String materialTypeName,@Param("id") int id);

}